<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        body {
            margin: 0; /*去掉自带的8个像素外边距*/
            background-color: darkseagreen;
            background-size: 100% 900px; /*设置背景为封面*/
            text-align: center;
            background-repeat: no-repeat;

        }

        h1 {
            font-size: 72px;
            color: #0096dc;
            margin-bottom: 0; /*去掉下外边距*/
        }

        img {
            width: 100px
        }

        h2 {
            font-size: 32px;
            color: aliceblue;
            margin-bottom: 0;
            font-weight: normal;
            margin-top: 0px;
            margin-bottom: 0px;
        }

        .el-icon-user {
            font-size: 100px;
            color: green;
            margin-bottom: 0px;
            padding-bottom: 0px;
        }

        .elcard {
            background-color: darkseagreen;
        }

        #boxs {
            margin-top: 100px;
        }
    </style>
</head>
<body>
<div id="app">
    <div id="boxs">
        <div style="margin-bottom: 0px">
            <i class="el-icon-user" style="size: 100px;border: green solid 5px;border-radius: 50%;width: 120px;height: 120px"></i>
        </div>
        <h2>用户登录</h2>
        <el-card style="width: 600px;height: 300px;
    margin: 0 auto;background-color: darkseagreen;border: none; box-shadow: none" class="elcard">

            <!--label-width="55px" 让lable和文本框显示在一行之内-->
            <el-form label-width="55px" style="width: 400px;margin: 10px auto;" >
                <el-form-item label="用户名">
                    <el-input type="text" v-model="user.username" placeholder="请输入用户名"></el-input>
                </el-form-item>
                <el-form-item label="密码">
                    <el-input type="password" v-model="user.password" placeholder="请输入密码"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit"
                               style="position:relative;width: 350px;background-color: orangered;border: none">登录
                    </el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
</div>
</body>
<!--引入axios和vue框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: {
            user: {username: "", password: ""}
        },
        methods: {
            onSubmit() {
                //发出异步请求
                let url = "http://localhost:9075/user/login";
                axios.post(url, this.user).then(function (response) {
                    let responseBody = response.data;
                    if (responseBody.state == 20000) {
                        v.$message({
                            message: "登陆成功",
                            type: "success"
                        });
                        location.href="/index.html"; //跳转到首页
                    } else {
                        v.$message.error("登陆失败");
                    }
                })
            }
        }
        /* created:function () {
             //取出cookie里面的数据 显示到页面中
             //username=admin; password=123456
             let arr = document.cookie.split(";");
             for (let cookie of arr) {
                 let cookieArr = cookie.split("=");
                 let name = cookieArr[0].trim();
                 let value = cookieArr[1];
                 if (name=="username"){
                     this.user.username = value;
                 }else if(name=="password"){
                     this.user.password = value;
                 }
             }

         }*/
    })
</script>
</html>